#include "widget.h"
#include <QPushButton>
#include "userinfo.h"
#include "interface_control.h"


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , findu(nullptr)
    , friends(nullptr)
{
    this->resize(800,1200);
    this->setWindowTitle("用户主界面");
    Interface_Control::getControlptr()->setm_fr(this);

    //查询界面
    findu = new FindeUser();
    findu->setParent(this);
    findu->move(0,400);
    findu->hide();

    //好友界面
    friends = new Friends();
    friends->setParent(this);
    friends->move(0,400);



    //将friends指针传入界面管理
    Interface_Control::getControlptr()->setm_s(friends);

    QPushButton *fri_pb = new QPushButton(this);
    fri_pb->setText("好友");
    fri_pb->setGeometry(0,300,300,100);
    connect(fri_pb,&QPushButton::clicked,[=]{friends->show();});

    QPushButton *gro_pb = new QPushButton(this);
    gro_pb->setText("群聊");
    gro_pb->setGeometry(300,300,300,100);
    connect(gro_pb,&QPushButton::clicked,[=]{
        friends->hide();
        findu->hide();
                });

    QPushButton *add_fri = new QPushButton(this);
    add_fri->setText("添加好友");
    add_fri->setGeometry(600,300,200,100);
    connect(add_fri,&QPushButton::clicked,[=](){
        Interface_Control::getControlptr()->showm_find();
        Interface_Control::getControlptr()->hidem_fr();
    });

    UserInfo *userinfo = new UserInfo(this,Client_connet::Get_Connet()->me.name,Client_connet::Get_Connet()->me.ID);
    userinfo->move(0,0);


}

Widget::~Widget()
{
}

void Widget::flushedFind()
{
    //为界面插入数据并刷新
//    findu->allFind();
    friends->hide();
    findu->show();

    //清空查询数组
    Client_connet::Get_Connet()->clearfind_arr();
}

void Widget::flushedFre()
{
    findu->hide();
    friends->show();
}

